package array;

import java.util.ArrayList;

public class L59 {
    //不会
    public int[][] generateMatrix(int n) {
        int[][] ints = new int[n][n];
        int startx=0,starty=0;
        int offset=1;
        int count=1;
        int loop=1;
        int i,j;
        while (loop<=n/2){
            for (j=starty;j<n-offset;j++){
                ints[startx][j]=count++;
            }
            for (i=startx;i<n-offset;i++){
                ints[i][j]=count++;
            }
            for (;j>starty;j--){
                ints[i][j]=count++;
            }
            for (;i>startx;i--){
                ints[i][j]=count++;
            }
            offset++;
            startx++;
            starty++;
            loop++;
        }
        if (n%2==1){
            ints[startx][starty]=count;
        }
        return ints;

    }

}
